<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <input type="text" id="searchTxt">
  <button>搜索</button>
  <ul class="list">
    <li></li>
  </ul>
  <script src="./jquery-3.4.1.min.js"></script>
  <script>
    //  原生js jsonp
    // var script = document.createElement("script");
    // script.src = "http://suggest.taobao.com/sug?code=utf-8&q=耳机&callback=cb";
    // document.body.appendChild(script)
    // function cb(res) {
    //   console.log(res)
    // }
    // -----------------------------------
    $("button").click(function () {

      $.ajax({
        url: "http://suggest.taobao.com/sug?code=utf-8&callback=cb",
        type: "get",
        dataType: "jsonp",//jsonp请求必须写的参数
        data: {
          q: $("#searchTxt").val()
        },
        success: function (res) {
          console.log(res)
          var str = ''
          $.each(res.result, function (inde, ele) {
            str += `<li>${ele[0]}</li>`
          })
          $(".list").html(str)
        }
      })

    })




  </script>
</body>

</html>